

    PRESERVE8
    AREA SYS_Boot, CODE, READONLY

	EXPORT Boot_SYSboot_Startup
	EXPORT Boot_SYSirq_FIQ_Handler

	



    IMPORT SYSpost_Test[WEAK]
    IMPORT hc_warm_reset[WEAK]

    IMPORT SYSirq_IRQ_Handler
    IMPORT SYSirq_FIQ_Handler
    IMPORT udi_main_40_A_B   


    IMPORT SYSbuild_Info_Dummy[WEAK]
                                                  ; stripping vector table

;
; common ARM Definitions
;

MODE_USR    EQU    0x10
MODE_FIQ    EQU    0x11
MODE_IRQ    EQU    0x12
MODE_SVC    EQU    0x13
MODE_ABORT  EQU    0x14
MODE_UNDEF  EQU    0x15
MODE_SYS    EQU    0x1F

I_BIT       EQU    0x80
F_BIT       EQU    0x40


I_SEL       EQU    0x00400000
I_SAVE	EQU    0x00400004
; common ARM code
;
; THIS IS THE ENTRY POINT FOR THE ROM BUILD!!!
; On power-up, the flash is located at 0x00000000
; Program Counter starts at 0x00000000, and we jump to 
; high flash at 0x04000000

    
    EXPORT SYS_Vector_Init_Block
	ENTRY

SYS_Vector_Init_Block
    LDR PC, _Reset_Addr
    LDR PC, _Undefined_Addr
    LDR PC, _SWI_Addr
    LDR PC, _Prefetch_Abort_Addr
    LDR PC, _Data_Abort_Addr
    NOP
    LDR PC, _IRQ_Addr ;restore for current hardware
    LDR PC, _FIQ_Addr ;restore for current hardware
    
   

_Reset_Addr            DCD Boot_SYSboot_Startup
_Undefined_Addr        DCD Boot_Undefined_Handler

_SWI_Addr              DCD Boot_SWI_Handler
_Prefetch_Abort_Addr   DCD Boot_Prefetch_Abort_Handler
_Data_Abort_Addr       DCD Boot_Abort_Handler
                       DCD 0                       ; Reserved Vector
_IRQ_Addr              DCD Boot_SYSirq_IRQ_Handler 
_FIQ_Addr              DCD Boot_SYSirq_FIQ_Handler	



P_40_A_SYSirq_FIQ_Handler EQU     0x00001E80
P_40_A_SYSirq_IRQ_Handler EQU     0x00001EA0
	
P_40_B_SYSirq_FIQ_Handler EQU     0x0003E240
P_40_B_SYSirq_IRQ_Handler EQU     0x0003E260
	
	
Boot_Undefined_Handler
Boot_SWI_Handler
Boot_Prefetch_Abort_Handler
Boot_Abort_Handler
    B Boot_Abort_Handler

          
;
; FUNCTION:     SYSboot_Startup
; DESCRIPTION:  Cold-Boot Startup routine
;
Boot_SYSboot_Startup
	    MOV R0, #0
	    MOV R1, #0
	    MOV R2, #0
	    MOV R3, #0
	    MOV R4, #0
	    MOV R5, #0
	    MOV R6, #0
	    MOV R7, #0
	    MOV R8, #0
	    MOV R9, #0
	    MOV R10, #0
	    MOV R11, #0
	    MOV R12, #0
		
	    
        BL      _SYSboot_Setup_Stacks_Disable_Intr
        BL      _SYSboot_ZI_Init
        BL      _SYSboot_Copy_CODE_To_SRAM

        LDR PC, =udi_main_40_A_B                         ; and go!
		
		
		
Boot_SYSirq_FIQ_Handler		
		STMFD SP!,{R0,R1}
		LDR R0,=I_SEL
		LDR R1,[R0]
		CMP R1,#0X01
		LDMFD SP!,{R0,R1}
		
		BEQ P_40_A_SYSirq_FIQ_Handler
		B P_40_B_SYSirq_FIQ_Handler
		
		
		
		
		
		

Boot_SYSirq_IRQ_Handler
		STMFD SP!,{R0,R1}
		LDR R0,=I_SEL
		LDR R1,[R0]
		CMP R1,#0X01
		LDMFD SP!,{R0,R1}
		
		BEQ P_40_A_SYSirq_IRQ_Handler
		B P_40_B_SYSirq_IRQ_Handler
		
		

_Dummy
        LDR PC, =SYS_Vector_Init_Block            ; dummy to prevent linker - not working for ADS linker
        LDR PC, =SYSbuild_Info_Dummy              ; dummy to prevent linker - not working for ADS linker
                                                  ; stripping vector table
_SYSboot_halt   B       _SYSboot_halt             ; should never reach here!!!


; **********************************************************************

;
; Need to include Target Specific ARM Code
;
       INCLUDE sys_boot_chimera.s                    

; **********************************************************************

;
; FUNCTION:     _SYSboot_Copy_CODE_To_SRAM
; DESCRIPTION:  copy main stack code from FLASH/ROM to SRAM
;
_SYSboot_Copy_CODE_To_SRAM

    IMPORT |Load$$RAM$$Base|[WEAK]         ; Load Addr of RAM (RW) 
    IMPORT |Image$$RAM$$Base|[WEAK]        ; Exec Addr of RAM (RW)
    IMPORT |Image$$RAM$$Length|[WEAK]      ; Length of RAM Exec (RW)

        LDR     R0, =|Load$$RAM$$Base|
        LDR     R1, =|Image$$RAM$$Base|
        MOV     R2, R1
        LDR     R4, =|Image$$RAM$$Length|
        ADD     R2, R2, R4
_copy                                       ; block copy function
        CMP r1, r2
        LDRLO   R3, [r0], #4
        STRLO   R3, [r1], #4
        BLO     _copy
        ;MOV     PC, LR
		BX lr

		mov r0,#1

;
; Generic ARM routines to setup the LSRAM and SRAM and jump into C code
;

; FUNCTION:     _SYSboot_ZI_Init
; DESCRIPTION:  Initialise Zero-Init Data Segment
;

_SYSboot_ZI_Init

    IMPORT |Image$$RAM$$ZI$$Base|    ; Exec Addr of RAM (ZI)
    IMPORT |Image$$RAM$$ZI$$Length|  ; Length of RAM Exec (ZI)
		
        LDR R2, =|Image$$RAM$$ZI$$Length|
        LDR R0, =|Image$$RAM$$ZI$$Base|
        MOV R1, R0
        ADD R1, R1, R2
        MOV R2, #0
_ZI_Loop
        CMP R0, R1
        STRLO R2, [R0], #4
        BLO _ZI_Loop
		;MOV PC, LR
		BX lr


        
        
        

    EXPORT __user_initial_stackheap


__user_initial_stackheap    
    LDR   r0,=bottom_of_heap
    ;MOV   pc,lr
	BX lr


__rt_div0
        B       __rt_div0      
          
        AREA    Myheap, DATA, NOINIT, ALIGN=2
bottom_of_heap     SPACE   256  ;



    END
